package com.aboo.file1;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

public class WriteFile {

    public static void main(String[] args) throws Exception {
        String file = "D://file1.txt";
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false)));
        WriteKit writeKit = new WriteKit(bw);

        ExecutorService executor = Executors.newFixedThreadPool(8);
        List<Future<Boolean>> taskList = new ArrayList<>(8);
        for (int i = 0; i < 5; i++) {
            Future<Boolean> future = executor.submit(new WirteCallable(writeKit));
            taskList.add(future);
        }

        for (Future<Boolean> task : taskList) {
            System.out.println(task.get(10L, TimeUnit.SECONDS));
        }
        bw.close();
        executor.shutdown();
    }

}
